﻿@model List<nwrole.toolbox.sync.entity.SyncEntity>

@{
    ViewBag.Title = "SchemaIndex";
}

<div>
    <table class="box">
        <tr>
            <th>Namn</th>
            <th>Tabell</th>
            <th>Importerad</th>
            <th>Val</th>
        </tr>
		@{ bool even = true; }
        @foreach (var e in Model)
        {        
            <tr @((even = !even) ? "class=even" : "")>
                <td class="form">
                    <a href="@Url.Action("schemashow", new {id=e.Id, type=@e.Type})">:@e.Name</a>
                </td>        
                <td class="form">
                    @e.SourceTableName
                </td>        
                <td class="form">
                    @((e.ImportDat!=null)?e.ImportDat.ToString() : "")
                </td>        
                <td class="form">
                    <a id="importSchemaLink" href="" onclick="return ImportSchema(this, @e.Id, @e.Type);">Importera</a>
                </td>        

            </tr>
        }
    </table>    
</div>
    

<script type="text/javascript">
    function ToggleSyncEnabled(obj, colId) {
        $.get('@Url.Action("ToggleSyncEnabled")', { id: colId, x: Math.random() }, function (result) {
            if (result.success) {
                if (result.newValue) {
                    $(obj).text('True');
                } else {
                    $(obj).text('False');
                }
            }
            else {
                alert(result.success);
            }
        });
        return false;
    }

    function ImportSchema(obj, id, type) {
        $.get('@Url.Action("ImportSchema")', { id: id, type: type, x: Math.random() }, function (result) {
            if (result.success) {
                alert("done");
                $('importSchemaLink').text('Done');
            }
            else {
                alert(result.success);
            }
        });
        return false;
    }
</script>